package com.hxx.controller;

import com.hxx.domain.Person;
import com.hxx.service.PersonService;
import com.hxx.utils.R;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class PersonController {
    @Autowired
    private PersonService personService;

    /**
     * 查询所有用户信息
     * @return
     */
    @GetMapping("/findAll")
    public R findAll() {
        return R.ok()
                .data("list", personService.findAll());
    }
    /**
     * 查询单个用户信息
     * @param id
     * @return
     */
    @GetMapping("/findOne")
    public R findOne(int id) {
        return R.ok()
                .data("person", personService.findById(id));
    }
    /**
     * 新增用户信息
     * @param person
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody Person person) {
        personService.save(person);
        return R.ok();
    }
    /**
     * 更新用户信息
     * @param person
     * @return
     */
    @PutMapping("/update")
    public R update(@RequestBody Person person) {
        personService.update(person);
        return R.ok();
    }
    /**
     * 删除用户信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable int id) {
        personService.delete(id);
        return R.ok();
    }
}
























